import { getAction } from '@/api/manage'
export const CodesMixin = {
  data() {
    return {
      codeUrl: '/manage/codeInfo/queryByTypes',
      codes: {},
    }
  },
  methods: {
    async fetchCodes(types) {
      let res = await getAction(this.codeUrl, { types: types.join(',') })
      if (res.success) {
        this.codes = { ...this.codes, ...res.result }
      }
    },
    getCodeNames(value, type) {
      if (this.codes[type]) {
        if (value || value == 0) {
          let codeNames = []
          this.codes[type].forEach((element) => {
            if ((',' + value + ',').indexOf(',' + element.code + ',') > -1) {
              codeNames.push(element.name)
            }
          })
          return codeNames.join(',')
        }
      }
      return ''
    },
  },
}
